/* HashSet<GtkConstraintGuide> */
GHashTable *guides;
+
+ GListStore *constraints_observer;
+ GListStore *guides_observer;
};
G_DEFINE_TYPE (GtkConstraintLayoutChild, gtk_constraint_layout_child, GTK_TYPE_LAYOUT_CHILD)
{
GtkConstraintLayout *self = GTK_CONSTRAINT_LAYOUT (gobject);
+ if (self->constraints_observer)
+ {
+ g_list_store_remove_all (self->constraints_observer);
+ g_object_remove_weak_pointer ((GObject *)self->constraints_observer,
+ (gpointer *)&self->constraints_observer);
+ }
+ if (self->guides_observer)
+ {
+ g_list_store_remove_all (self->guides_observer);
+ g_object_remove_weak_pointer ((GObject *)self->guides_observer,
+ (gpointer *)&self->guides_observer);
+ }
+
g_clear_pointer (&self->bound_attributes, g_hash_table_unref);
g_clear_pointer (&self->constraints, g_hash_table_unref);
g_clear_pointer (&self->guides, g_hash_table_unref);
layout_add_constraint (layout, constraint);
g_hash_table_add (layout->constraints, constraint);
+ if (layout->constraints_observer)
+ g_list_store_append (layout->constraints_observer, constraint);
gtk_layout_manager_layout_changed (GTK_LAYOUT_MANAGER (layout));
}
+static void
+list_store_remove_item (GListStore *store,
+ gpointer item)
+{
+ int n_items;
+ int i;
+
+ n_items = g_list_model_get_n_items (G_LIST_MODEL (store));
+ for (i = 0; i < n_items; i++)
+ {
+ gpointer *model_item = g_list_model_get_item (G_LIST_MODEL (store), i);
+ g_object_unref (model_item);
+ if (item == model_item)
+ {
+ g_list_store_remove (store, i);
+ break;
+ }
+ }
+}
+
/**
* gtk_constraint_layout_remove_constraint:
* @layout: a #GtkConstraintLayout
gtk_constraint_detach (constraint);
g_hash_table_remove (layout->constraints, constraint);
+ if (layout->constraints_observer)
+ list_store_remove_item (layout->constraints_observer, constraint);
gtk_layout_manager_layout_changed (GTK_LAYOUT_MANAGER (layout));
}
gtk_constraint_detach (constraint);
g_hash_table_iter_remove (&iter);
}
+ if (layout->constraints_observer)
+ g_list_store_remove_all (layout->constraints_observer);
gtk_layout_manager_layout_changed (GTK_LAYOUT_MANAGER (layout));
}
gtk_constraint_guide_set_layout (guide, layout);
g_hash_table_add (layout->guides, guide);
+ if (layout->guides_observer)
+ g_list_store_append (layout->guides_observer, guide);
gtk_layout_manager_layout_changed (GTK_LAYOUT_MANAGER (layout));
}
gtk_constraint_guide_set_layout (guide, NULL);
g_hash_table_remove (layout->guides, guide);
+ if (layout->guides_observer)
+ list_store_remove_item (layout->guides_observer, guide);
gtk_layout_manager_layout_changed (GTK_LAYOUT_MANAGER (layout));
}
layout_add_constraint (layout, constraint);
g_hash_table_add (layout->constraints, constraint);
+ if (layout->constraints_observer)
+ g_list_store_append (layout->constraints_observer, constraint);
res = g_list_prepend (res, constraint);
}
return res;
}
+
+/**
+ * gtk_constraint_layout_observe_constraints:
+ * @layout: a #GtkConstraintLayout
+ *
+ * Returns a #GListModel to track the constraints that are
+ * part of @layout.
+ *
+ * Calling this function will enable extra internal bookkeeping
+ * to track constraints and emit signals on the returned listmodel.
+ * It may slow down operations a lot.
+ *
+ * Applications should try hard to avoid calling this function
+ * because of the slowdowns.
+ *
+ * Returns: (transfer full): a #GListModel tracking @layout's
+ * constraints
+ */
+GListModel *
+gtk_constraint_layout_observe_constraints (GtkConstraintLayout *layout)
+{
+ GHashTableIter iter;
+ gpointer key;
+
+ if (layout->constraints_observer)
+ return g_object_ref (G_LIST_MODEL (layout->constraints_observer));
+
+ layout->constraints_observer = g_list_store_new (GTK_TYPE_CONSTRAINT);
+ g_object_add_weak_pointer ((GObject *)layout->constraints_observer,
+ (gpointer *)&layout->constraints_observer);
+
+ g_hash_table_iter_init (&iter, layout->constraints);
+ while (g_hash_table_iter_next (&iter, &key, NULL))
+ {
+ GtkConstraint *constraint = key;
+ g_list_store_append (layout->constraints_observer, constraint);
+ }
+
+ return G_LIST_MODEL (layout->constraints_observer);
+}
+
+/**
+ * gtk_constraint_layout_observe_guides:
+ * @layout: a #GtkConstraintLayout
+ *
+ * Returns a #GListModel to track the guides that are
+ * part of @layout.
+ *
+ * Calling this function will enable extra internal bookkeeping
+ * to track guides and emit signals on the returned listmodel.
+ * It may slow down operations a lot.
+ *
+ * Applications should try hard to avoid calling this function
+ * because of the slowdowns.
+ *
+ * Returns: (transfer full): a #GListModel tracking @layout's
+ * guides
+ */
+GListModel *
+gtk_constraint_layout_observe_guides (GtkConstraintLayout *layout)
+{
+ GHashTableIter iter;
+ gpointer key;
+
+ if (layout->guides_observer)
+ return g_object_ref (G_LIST_MODEL (layout->guides_observer));
+
+ layout->guides_observer = g_list_store_new (GTK_TYPE_CONSTRAINT_GUIDE);
+ g_object_add_weak_pointer ((GObject *)layout->guides_observer,
+ (gpointer *)&layout->guides_observer);
+
+ g_hash_table_iter_init (&iter, layout->guides);
+ while (g_hash_table_iter_next (&iter, &key, NULL))
+ {
+ GtkConstraintGuide *guide = key;
+ g_list_store_append (layout->guides_observer, guide);
+ }
+
+ return G_LIST_MODEL (layout->guides_observer);
+}